const app = getApp()

Page({
  data: {

    
    onLoad: function () { },
    
  },
  //评论
  ping: function (e) {
    var that = this;
    console.log(e.currentTarget.dataset.id)
    that.setData({
      llbView: true,
      pid: e.currentTarget.dataset.id,
      to_user_id: e.currentTarget.dataset.user
    })
  },
  //点赞
  zan: function (e) {
    console.log(e)
    var that = this;
    wx.request({
      url: 'http://111.231.237.236/getlist',
      method: "POST",
      data: {
        "column": "Reply",
        "user_id": wx.getStorageSync('user_id'),
        "id": e.currentTarget.dataset.id
      },
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      },
      success: function (res) {
        var data = that.data.yanlist
        console.log(data)
        if (res.data != null) {
          if (res.data.indexOf(wx.getStorageSync('user_id')) == "-1") {
            for (var i in data.list) {
              if (data.list[i]._child) {
                for (var j in data.list[i]._child) {
                  if (e.currentTarget.dataset.id == data.list[i]._child[j].id) {
                    data.list[i]._child[j].cnmView = true
                    data.list[i]._child[j].like_count = parseInt(data.list[i]._child[j].like_count) + 1
                  }
                }
              }
            }
            that.setData({
              yanlist: data
            })
          }
        } else {
          for (var i in data.list) {
            if (data.list[i]._child) {
              for (var j in data.list[i]._child) {
                if (e.currentTarget.dataset.id == data.list[i]._child[j].id) {
                  data.list[i]._child[j].cnmView = true
                  data.list[i]._child[j].like_count = parseInt(data.list[i]._child[j].like_count) + 1
                }
              }
            }
          }
          that.setData({
            yanlist: data
          })
        }
      }
    })
  },
onLoad: function () {
  console.log('onLoad')
  
  var that = this
  wx.request({
    url: 'http://139.199.105.136/lovewall/show', //仅为示例，并非真实的接口地址
    data: {},
    header: {
      'content-type': 'application/json'
    },
    success: function (res) {
      var data = res.data;
      var numb = 1;
      for (var i in data) {
        if (data[numb] != null) { numb++; }

      }
      var dat = new Array();

      var len = (numb - 2);

      for (var nu = 0; nu < len; nu++) {

        dat[nu] = data[len - nu];

        console.log(dat)

      }

      console.log(res.data)
      
      var num=0;
     
      var people=new Array();
      for (var i in dat) {
        if (dat[i].like_count >= 1) {
          
          people[num]=dat[i];
          num++;
        }}
      
      console.log(res.data)
      that.setData({
        Industry: people
      })
    },
    fail: function (err) {
      console.log(err)
    }
  })
},
/**
  * 生命周期函数--监听页面初次渲染完成
  */
onReady: function () {

},

/**
 * 生命周期函数--监听页面显示
 */
onShow: function () {

},

/**
 * 生命周期函数--监听页面隐藏
 */
onHide: function () {

},

/**
 * 生命周期函数--监听页面卸载
 */
onUnload: function () {

},

/**
 * 页面相关事件处理函数--监听用户下拉动作
 */
onPullDownRefresh: function () {

},

/**
 * 页面上拉触底事件的处理函数
 */
onReachBottom: function () {

},

/**
 * 用户点击右上角分享
 */
onShareAppMessage: function () {

},
// 查看详情
showDetail(event) {
  wx.navigateTo({
    url: '../entry/entry?id=' + event.currentTarget.id,
  });
},
onPullDownRefresh() {
  var that = this
  wx.request({
    url: 'http://139.199.105.136/lovewall/show', //仅为示例，并非真实的接口地址
    data: {},
    header: {
      'content-type': 'application/json'
    },
    success: function (res) {


      console.log(res.data)
      that.setData({
        Industry: res.data
      })
    },
    fail: function (err) {
      console.log(err)
    }
  })
}
})